<?php

// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action {

    public function _initialize() {
        $sort = M("sort");
        $news = M("news");
        $sortid = $_GET['id'];
        $flag = $_GET['flag'];
        $sortinfo = $sort->where('flag='.$flag.' and sort=0')->select();
        $newhit = $news->where('flag=3 and shei=1')->order('id desc')->limit('10')->select();
        $this->assign('sortinfo', $sortinfo);
        $this->assign('flag',$flag);
        $this->assign('newhit', $newhit);
        $this->assign('sortid', $sortid);
    }

    public function index() {
//        echo session('member_name');
        $news = M("news");
        $newslist = $news->where('sort=5 and flag=1 and shei!=3')->order('id desc')->limit('15')->select();
        $newsjj = $news->where('sort=5 and flag=1 and hy=1 and shei!=3')->order('id desc')->limit('8')->select();
        $newsdb = $news->where('sort=5 and flag=1 and hy=2 and shei!=3')->order('id desc')->limit('8')->select();
        $newstp = $news->where('sort=8 and flag=1 and shei!=3')->order('id desc')->limit('10')->select();
        $newsmc = $news->where('sort=13 and flag=1 and shei!=3')->order('id desc')->limit('10')->select();
        $newszt = $news->where('sort=6 and flag=1 and shei!=3')->order('id desc')->limit('4')->select();
        $this->assign('newslist', $newslist);
        $this->assign('newsjj', $newsjj);
        $this->assign('newsdb', $newsdb);
        $this->assign('newstp', $newstp);
        $this->assign('newsmc', $newsmc);
        $this->assign('newszt', $newszt);
        $this->display();
    }

    public function news() {
        $news = M("news");
        $newslist = $news->where('flag=2 and shei!=3')->order('id desc')->limit('20')->select();
        $newshit = $news->where('sort=1 and flag=2 and shei!=3')->order('id desc')->limit('4')->select();
        $newsjd = $news->where('sort=12 and flag=2 and shei!=3')->order('id desc')->limit('10')->select();
        $newszh = $news->where('sort=10 and flag=2 and shei!=3')->order('id desc')->limit('4')->select();
        $this->assign('newslist', $newslist);
        $this->assign('newshit', $newshit);
        $this->assign('newsjd', $newsjd);
        $this->assign('newszh', $newszh);
        $this->display();
    }

    public function head() {
        $this->display();
    }

    public function news_list($id) {
        import('ORG.Util.PageJh');
        $id = intval($id);
        $news = M("news");
        $xysort = M("xysort");
        $xid = $_GET['xid'];
        $xylist = $xysort->select();
        $q = empty($_GET['q']) ? 'true' : "title like '%" . $_GET['q'] . "%'";
        if (empty($xid)) {
            if ($id > 0) {
                $where = 'sort=' . $id . ' and shei=1 and ' . $q;
            } else {
                $where = $q;
            } $count = $news->where($where)->count();
            $Page = new PageJh($count, 10);
            $newslist = $news->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();
            if (empty($_GET['q']))
                $Page->parameter = 'id=' . $id; else
                $Page->parameter = 'id=' . $id . '&q=' . $_GET['q'];
        } else {
            if ($id > 0) {
                $where = 'sort=' . $id . ' and hy=' . $xid . ' and shei=1 and ' . $q;
            } else {
                $where = $q;
            } $count = $news->where($where)->count();
            $Page = new PageJh($count, 10);
            $newslist = $news->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();
            if (empty($_GET['q']))
                $Page->parameter = 'id=' . $id . '&xid=' . $xid; else
                $Page->parameter = 'id=' . $id . '&xid=' . $xid . '&q=' . $_GET['q'];
        }
        // 设置分页显示Ï
//        $Page->setConfig('header', '条数据');
//        $Page->setConfig('prev', '上一页');
//        $Page->setConfig('next', '下一页');
        $page = $Page->show();
        $this->assign('newsCount', $count);
        $this->assign("id", $id);
        $this->assign('xylist', $xylist);
        $this->assign("page", $page);
        $this->assign('newslist', $newslist);
        $this->display();
    }

    public function news_detail($id) {
        $news = M("news");
        $sort = M("sort");
        $newsinfo = $news->where('id=' . $id . ' and shei=1')->find();
        $sortinfo = $sort->where('id=' . $newsinfo['sort'])->find();
        $this->assign('sort', $sortinfo);
        $xgnews = $news->where('sort=' . $newsinfo['sort'] . ' and id!=' . $id . ' and shei=1')->order('id desc')->limit('10')->select();
        //上一篇
        $front = $news->where('sort=' . $newsinfo['sort'] . ' and id<' . $id . ' and shei=1')->order('id desc')->limit('1')->find();
        $f = !$front ? '没有了' : '<A href="' . __URL__ . '/news_detail?id=' . $front['id'] . '">' . $front['title'] . '</A>';
        $this->assign('front', $f);
        //下一篇
        $after = $news->where('sort=' . $newsinfo['sort'] . ' and id>' . $id . ' and shei=1')->order('id asc')->limit('1')->find();
        $a = !$after ? '没有了' : '<A href="' . __URL__ . '/news_detail?id=' . $after['id'] . '">' . $after['title'] . '</A>';
        $this->assign('after', $a);
        $contentlist = explode("</p>", $newsinfo['content'], 2);
        $this->assign('xgnews', $xgnews);
        $this->assign('contentlist', $contentlist);
        $this->assign('newsinfo', $newsinfo);
        $this->display();
    }

}